package net.dgg.rz.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;

/**
 * @Title: InitComponent
 * @Description:
 * @Auther: 汤宏
 * @Date: 2018/05/03 15:02
 */
@Component
public class InitComponent {
    @Autowired
    private ServletContext applicationScope;
    @Value("${baseStaicUrl}")
    private String baseStaicUrl;
    @Value("${cmsBaseUrl}")
    private String cmsBaseUrl;
    @Value("${uploadBaseUrl}")
    private String uploadBaseUrl;
    @Value("${ucApiUrl}")
    private String ucApiUrl;
    @Value("${busBaseUrl}")
    private String busBaseUrl;
    @Value("${orfApiUrl}")
    private String orfApiUrl;
    @Value("${ibosschan}")
    private String ibosschan;
    @Value("${site.domain}")
    private String siteDomain;
    @Value("${sys.version}")
    private String version;
    @Value("${bottomApiUrl}")
    private String bottomApiUrl;

    public static String appId;
    public static String mqIp;
    public static String mqShIp;
    public static String qdsApiUrl;
    @Value("${dgg.appId}")
    private String appIdTmp;
    @Value("${nature.messagequeue.host}")
    private String mqIpTmp;
    @Value("${nature.messagequeue.host1}")
    private String mqShIpTmp;
    @Value("${qdsApiUrl}")
    private String qdsApiUrlTmp;
    @Value("${gatewayFile}")
    private String gatewayFile;
    @Value("${uploadFile}")
    private String uploadFile;
    @Value("${getFileId}")
    private String getFileId;
    @Value("${deleteFile}")
    private String deleteFile;
    @Value("${download}")
    private String download;

    // 初始化时执行该方法
    @PostConstruct
    public void init() {
        applicationScope.setAttribute("baseStaticUrl", baseStaicUrl);
        applicationScope.setAttribute("cmsBaseUrl", cmsBaseUrl);
        applicationScope.setAttribute("uploadBaseUrl", uploadBaseUrl);
        applicationScope.setAttribute("ucApiUrl", ucApiUrl);
        applicationScope.setAttribute("orfApiUrl", orfApiUrl);
        applicationScope.setAttribute("bottomApiUrl", bottomApiUrl);
        applicationScope.setAttribute("ibosschan", ibosschan);
        applicationScope.setAttribute("busBaseUrl", busBaseUrl);
        //applicationScope.setAttribute("version", String.valueOf(System.currentTimeMillis()));
        applicationScope.setAttribute("siteDomain", siteDomain);
        applicationScope.setAttribute("version", version);
        applicationScope.setAttribute("gatewayFile", gatewayFile);
        applicationScope.setAttribute("uploadFile", uploadFile);
        applicationScope.setAttribute("getFileId", getFileId);
        applicationScope.setAttribute("deleteFile", deleteFile);
        applicationScope.setAttribute("download", download);
        appId = appIdTmp;
        mqIp = mqIpTmp;
        mqShIp = mqShIpTmp;
        qdsApiUrl = qdsApiUrlTmp;
    }
}
